package mysql

import (
	"gorm.io/gorm"
)

type Rob struct {
	gorm.Model
	Name      string  `gorm:"type:varchar(30);comment:课程名称"`
	Cover     string  `gorm:"type:varchar(255);comment:课程封面"`
	Price     float64 `gorm:"type:decimal(10,2);comment:原价"`
	NowPrice  float64 `gorm:"type:decimal(10,2);comment:现价"`
	StartTime string  `gorm:"type:datetime;comment:抢购开始时间"`
	EndTime   string  `gorm:"type:datetime;comment:抢购结束时间"`
}

func (Rob) TableName() string {
	return "rob"
}

func (r *Rob) AddRob() error {
	return DB.Create(&r).Error
}

func (r *Rob) Find(robId int64) (result Rob, err error) {
	err = DB.Where("id=?", robId).Find(&result).Error
	if err != nil {
		return Rob{}, err
	}
	return result, nil
}
